<!DOCTYPE html>
<html lang="en">

    <head>
        <meta charset="UTF-8" />
        <link rel="stylesheet" href="styles/style.css">
        <link rel="stylesheet" href="styles/theme/atom-one-dark.css">
        <title>例子23-ES6/7常用语法介绍</title>
    </head>

    <body>
        <pre>
            <code>
                // 例子23

                // 将类数组对象转换为真正的数组
                let arrayLike = {
                    '0': 'a',
                    '1': 'b',
                    '2': 'c',
                    length: 3
                };

                // ES5
                var arr1 = [].slice.call(arrayLike); // ["a", "b", "c"]

                // ES6
                let arr2 = Array.from(arrayLike); // ["a", "b", "c"]

                //--------------------------------------------------------------------------

                // 将类数组对象arguments转换为真正的数组对象
                function fn() {
                    // ES5
                    var args = [].slice.call(arguments);
                    // ES6
                    let args = Array.from(arguments);
                    // ...
                }

                //--------------------------------------------------------------------------

                let arrayLike = {
                    '0': 0,
                    '1': 1,
                    '2': 2,
                    length: 3
                };

                Array.from(arrayLike, x => x * x); // [0, 1, 4]
                //相当于
                Array.from(arrayLike).map(x => x * x); // [0, 1, 4]
            </code>
        </pre>
        <script src="scripts/libs/highlight.pack.js"></script>
        <script src="scripts/23.js"></script>
        <script>
            hljs.initHighlightingOnLoad();
        </script>
    </body>

</html>